package com.yn.sys;

import com.yn.sys.tools.SerialPortTool;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class StartInit {

    @Value("${yn.serial.port.name}")
    private String clientSerialName;

    @Value("${yn.serial.port.bitrate}")
    private int bitrate;

    @PostConstruct
    public void start(){
        // 启动串口工具
        startSerialPortTool();
    }

    private void startSerialPortTool() {
        SerialPortTool handle = new SerialPortTool(clientSerialName, bitrate);
        System.out.println(clientSerialName);
        System.out.println(bitrate);
        int i = handle.init();
        if (i == 1) {
            // 线程启动
            handle.start();
        }
    }

}
